package o3rome;

import com.sun.media.sound.AiffFileReader;

/**
 * @author shkstart
 * @create 2021-12-28-14:35
 */
public class Rome01 {

    public static void main(String[] args) {
        int number = romanToInt("MCMXCIV");
        System.out.println(number);
    }


    public static int romanToInt(String s) {
        int number = 0;

        char[] romeArray = s.toCharArray();

        for (int i = 0; i < romeArray.length; i++) {

            if (i != romeArray.length - 1) {
                if (romeArray[i] == 'C' && romeArray[i + 1] == 'M') {
                    number += 900;
                    romeArray[i] = romeArray[i+1] = '0';
                }
                if (romeArray[i] == 'C' && romeArray[i + 1] == 'D') {
                    number += 400;
                    romeArray[i] = romeArray[i+1] = '0';
                }
                if (romeArray[i] == 'X' && romeArray[i + 1] == 'C') {
                    number += 90;
                    romeArray[i] = romeArray[i+1] = '0';
                }
                if (romeArray[i] == 'X' && romeArray[i + 1] == 'L') {
                    number += 40;
                    romeArray[i] = romeArray[i+1] = '0';
                }
                if (romeArray[i] == 'I' && romeArray[i + 1] == 'X') {
                    number += 9;
                    romeArray[i] = romeArray[i+1] = '0';
                }
                if (romeArray[i] == 'I' && romeArray[i + 1] == 'V') {
                    number += 4;
                    romeArray[i] = romeArray[i+1] = '0';
                }
            }

            switch (romeArray[i]) {
                case 'I':
                    number += 1;
                    break;
                case 'V':
                    number += 5;
                    break;
                case 'X':
                    number += 10;
                    break;
                case 'L':
                    number += 50;
                    break;
                case 'C':
                    number += 100;
                    break;
                case 'D':
                    number += 500;
                    break;
                case 'M':
                    number += 1000;
                    break;

            }
        }

        return number;
    }

}
